# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python


class Recipe(custom.GStreamer):
    name = 'gst-plugins-base-1.0'
    btype = BuildType.MESON
    tarball_checksum = '4093aa7b51e28fb24dfd603893fead8d1b7782f088b05ed0f22a21ef176fb5ae'
    meson_options = {# enabled plugins
                     'gl': 'enabled',
                     'libvisual': 'enabled',
                     'ogg': 'enabled',
                     'opus': 'enabled',
                     'pango': 'enabled',
                     'theora': 'enabled',
                     'vorbis': 'enabled',
                     # disabled plugins
                     'tremor': 'disabled'}
    deps = ['glib', 'gstreamer-1.0', 'libxml2', 'libogg', 'pango', 'libtheora',
            'libvisual', 'libvorbis', 'zlib', 'orc', 'opus', 'graphene',
            'libjpeg-turbo', 'libpng']
    platform_deps = {Platform.ANDROID: [ 'tremor' ], Platform.IOS: [ 'tremor' ] }
    use_system_libs = True

    files_bins = ['gst-discoverer-1.0', 'gst-play-1.0', 'gst-device-monitor-1.0']

    files_libs = ['libgstallocators-1.0',
                 'libgstapp-1.0', 'libgstaudio-1.0',
                 'libgstfft-1.0', 'libgstpbutils-1.0', 'libgstriff-1.0', 'libgstrtp-1.0',
                 'libgstrtsp-1.0', 'libgstsdp-1.0', 'libgsttag-1.0',
                 'libgstvideo-1.0', 'libgstgl-1.0']

    files_plugins_core = [
             'lib/gstreamer-1.0/libgstadder%(mext)s',
             'lib/gstreamer-1.0/libgstapp%(mext)s',
             'lib/gstreamer-1.0/libgstaudioconvert%(mext)s',
             'lib/gstreamer-1.0/libgstaudiomixer%(mext)s',
             'lib/gstreamer-1.0/libgstaudiorate%(mext)s',
             'lib/gstreamer-1.0/libgstaudioresample%(mext)s',
             'lib/gstreamer-1.0/libgstaudiotestsrc%(mext)s',
             'lib/gstreamer-1.0/libgstcompositor%(mext)s',
             'lib/gstreamer-1.0/libgstgio%(mext)s',
             'lib/gstreamer-1.0/libgstoverlaycomposition%(mext)s',
             'lib/gstreamer-1.0/libgstpango%(mext)s',
             'lib/gstreamer-1.0/libgstrawparse%(mext)s',
             'lib/gstreamer-1.0/libgsttypefindfunctions%(mext)s',
             'lib/gstreamer-1.0/libgstvideoconvert%(mext)s',
             'lib/gstreamer-1.0/libgstvideorate%(mext)s',
             'lib/gstreamer-1.0/libgstvideoscale%(mext)s',
             'lib/gstreamer-1.0/libgstvideotestsrc%(mext)s',
             'lib/gstreamer-1.0/libgstvolume%(mext)s',
    ]

    files_plugins_core_devel = [
             'lib/gstreamer-1.0/libgstadder.a', 'lib/gstreamer-1.0/libgstadder.la',
             'lib/gstreamer-1.0/libgstapp.a', 'lib/gstreamer-1.0/libgstapp.la',
             'lib/gstreamer-1.0/libgstaudioconvert.a', 'lib/gstreamer-1.0/libgstaudioconvert.la',
             'lib/gstreamer-1.0/libgstaudiomixer.a', 'lib/gstreamer-1.0/libgstaudiomixer.la',
             'lib/gstreamer-1.0/libgstaudiorate.a', 'lib/gstreamer-1.0/libgstaudiorate.la',
             'lib/gstreamer-1.0/libgstaudioresample.a', 'lib/gstreamer-1.0/libgstaudioresample.la',
             'lib/gstreamer-1.0/libgstaudiotestsrc.a', 'lib/gstreamer-1.0/libgstaudiotestsrc.la',
             'lib/gstreamer-1.0/libgstcompositor.a', 'lib/gstreamer-1.0/libgstcompositor.la',
             'lib/gstreamer-1.0/libgstgio.a', 'lib/gstreamer-1.0/libgstgio.la',
             'lib/gstreamer-1.0/libgstoverlaycomposition.a', 'lib/gstreamer-1.0/libgstoverlaycomposition.la',
             'lib/gstreamer-1.0/libgstpango.a', 'lib/gstreamer-1.0/libgstpango.la',
             'lib/gstreamer-1.0/libgstrawparse.a', 'lib/gstreamer-1.0/libgstrawparse.la',
             'lib/gstreamer-1.0/libgsttypefindfunctions.a', 'lib/gstreamer-1.0/libgsttypefindfunctions.la',
             'lib/gstreamer-1.0/libgstvideoconvert.a', 'lib/gstreamer-1.0/libgstvideoconvert.la',
             'lib/gstreamer-1.0/libgstvideorate.a', 'lib/gstreamer-1.0/libgstvideorate.la',
             'lib/gstreamer-1.0/libgstvideoscale.a', 'lib/gstreamer-1.0/libgstvideoscale.la',
             'lib/gstreamer-1.0/libgstvideotestsrc.a', 'lib/gstreamer-1.0/libgstvideotestsrc.la',
             'lib/gstreamer-1.0/libgstvolume.a', 'lib/gstreamer-1.0/libgstvolume.la',
    ]

    files_plugins_playback = [
             'lib/gstreamer-1.0/libgstplayback%(mext)s',
    ]

    files_plugins_playback_devel = [
             'lib/gstreamer-1.0/libgstplayback.a', 'lib/gstreamer-1.0/libgstplayback.la',
    ]

    # Not used currently
    files_plugins_encoding = [
             'lib/gstreamer-1.0/libgstencoding%(mext)s',
    ]

    files_plugins_encoding_devel = [
             'lib/gstreamer-1.0/libgstencoding.a', 'lib/gstreamer-1.0/libgstencoding.la',
    ]

    files_plugins_codecs = [
             'lib/gstreamer-1.0/libgstsubparse%(mext)s',
             'lib/gstreamer-1.0/libgstogg%(mext)s',
             'lib/gstreamer-1.0/libgsttheora%(mext)s',
             'lib/gstreamer-1.0/libgstvorbis%(mext)s',
             'lib/gstreamer-1.0/libgstopus%(mext)s',
    ]

    files_plugins_codecs_devel = [
             'lib/gstreamer-1.0/libgstsubparse.a', 'lib/gstreamer-1.0/libgstsubparse.la',
             'lib/gstreamer-1.0/libgstogg.a', 'lib/gstreamer-1.0/libgstogg.la',
             'lib/gstreamer-1.0/libgsttheora.a', 'lib/gstreamer-1.0/libgsttheora.la',
             'lib/gstreamer-1.0/libgstvorbis.a', 'lib/gstreamer-1.0/libgstvorbis.la',
             'lib/gstreamer-1.0/libgstopus.a', 'lib/gstreamer-1.0/libgstopus.la',
    ]

    files_plugins_vis = [
             'lib/gstreamer-1.0/libgstlibvisual%(mext)s',
    ]

    files_plugins_vis_devel = [
             'lib/gstreamer-1.0/libgstlibvisual.a', 'lib/gstreamer-1.0/libgstlibvisual.la',
    ]

    files_plugins_devel = [
            'include/gstreamer-1.0/gst/allocators',
            'include/gstreamer-1.0/gst/app',
            'include/gstreamer-1.0/gst/audio',
            'include/gstreamer-1.0/gst/fft',
            'include/gstreamer-1.0/gst/gl',
            'lib/gstreamer-1.0/include/gst/gl',
            'include/gstreamer-1.0/gst/pbutils',
            'include/gstreamer-1.0/gst/riff',
            'include/gstreamer-1.0/gst/rtp',
            'include/gstreamer-1.0/gst/rtsp',
            'include/gstreamer-1.0/gst/sdp',
            'include/gstreamer-1.0/gst/tag',
            'include/gstreamer-1.0/gst/video',
            'lib/pkgconfig/gstreamer-allocators-1.0.pc',
            'lib/pkgconfig/gstreamer-app-1.0.pc',
            'lib/pkgconfig/gstreamer-audio-1.0.pc',
            'lib/pkgconfig/gstreamer-fft-1.0.pc',
            'lib/pkgconfig/gstreamer-gl-1.0.pc',
            'lib/pkgconfig/gstreamer-pbutils-1.0.pc',
            'lib/pkgconfig/gstreamer-riff-1.0.pc',
            'lib/pkgconfig/gstreamer-rtp-1.0.pc',
            'lib/pkgconfig/gstreamer-rtsp-1.0.pc',
            'lib/pkgconfig/gstreamer-sdp-1.0.pc',
            'lib/pkgconfig/gstreamer-tag-1.0.pc',
            'lib/pkgconfig/gstreamer-video-1.0.pc',
            'lib/pkgconfig/gstreamer-plugins-base-1.0.pc',
    ]

    files_plugins_net = [
            'lib/gstreamer-1.0/libgsttcp%(mext)s',
    ]

    files_plugins_net_devel = [
            'lib/gstreamer-1.0/libgsttcp.a', 'lib/gstreamer-1.0/libgsttcp.la',
    ]

    files_plugins_sys = []

    files_plugins_sys_devel = []

    platform_files_plugins_codecs = {
        Platform.ANDROID: [
             'lib/gstreamer-1.0/libgstivorbisdec%(mext)s',
            ],
        Platform.IOS: [
             'lib/gstreamer-1.0/libgstivorbisdec%(mext)s',
            ]
    }

    platform_files_plugins_codecs_devel = {
        Platform.ANDROID: [
             'lib/gstreamer-1.0/libgstivorbisdec.a', 'lib/gstreamer-1.0/libgstivorbisdec.la',
            ],
        Platform.IOS: [
             'lib/gstreamer-1.0/libgstivorbisdec.a', 'lib/gstreamer-1.0/libgstivorbisdec.la',
            ]
    }

    platform_files_plugins_sys = {
        Platform.LINUX: [
             'lib/gstreamer-1.0/libgstopengl%(mext)s',
            ],
        Platform.WINDOWS: [
             'lib/gstreamer-1.0/libgstopengl%(mext)s',
            ],
        Platform.DARWIN: [
             'lib/gstreamer-1.0/libgstopengl%(mext)s',
            ],
        Platform.IOS: [
             'lib/gstreamer-1.0/libgstopengl%(mext)s',
            ],
        Platform.ANDROID: [
             'lib/gstreamer-1.0/libgstopengl%(mext)s',
            ]
    }

    platform_files_plugins_sys_devel = {
        Platform.LINUX: [
             'lib/gstreamer-1.0/libgstopengl.a', 'lib/gstreamer-1.0/libgstopengl.la',
            ],
        Platform.WINDOWS: [
             'lib/gstreamer-1.0/libgstopengl.a', 'lib/gstreamer-1.0/libgstopengl.la',
            ],
        Platform.DARWIN: [
             'lib/gstreamer-1.0/libgstopengl.a', 'lib/gstreamer-1.0/libgstopengl.la',
            ],
        Platform.IOS: [
             'lib/gstreamer-1.0/libgstopengl.a', 'lib/gstreamer-1.0/libgstopengl.la',
            ],
        Platform.ANDROID: [
             'lib/gstreamer-1.0/libgstopengl.a', 'lib/gstreamer-1.0/libgstopengl.la',
            ]
    }

    files_lang = ['gst-plugins-base-1.0']

    files_typelibs = [
        'GstAllocators-1.0',
        'GstApp-1.0',
        'GstGL-1.0',
        'GstPbutils-1.0',
#        'GstRiff-1.0',         Gir disabled due to incompatibilities
        'GstRtp-1.0',
        'GstRtsp-1.0',
        'GstSdp-1.0',
        'GstTag-1.0',
        'GstVideo-1.0',
        'GstAudio-1.0'
        ]

    def prepare(self):
        # Disable Cocoa NSApp integration since we enable the Cocoa MainLoop
        # integration in the GLib recipe
        if self.config.target_platform in (Platform.DARWIN, Platform.IOS):
            self.append_env('CFLAGS', '-DGSTREAMER_GLIB_COCOA_NSAPPLICATION=1')
            self.append_env('OBJCFLAGS', '-DGSTREAMER_GLIB_COCOA_NSAPPLICATION=1')

        self.enable_plugin('cdparanoia', 'sys', 'cdparanoia', dep='cdparanoia')
        self.enable_plugin('ximagesink', 'sys', 'x11')
        self.enable_plugin('xvimagesink', 'sys', 'x11', option='xvideo')
        self.enable_plugin('alsa', 'sys', 'alsa')

        if self.config.variants.nodebug:
            self.append_env('CFLAGS', '-DGST_LEVEL_MAX=GST_LEVEL_FIXME')

        if self.config.target_platform in (Platform.ANDROID, Platform.IOS):
            self.meson_options['tremor'] = 'enabled'

        # Our ancient toolchain manages to hang while linking one of the tests
        # if this is enabled. XXX: Revisit when the toolchain is updated:
        # https://gitlab.freedesktop.org/gstreamer/cerbero/merge_requests/69
        if self.config.target_platform == Platform.WINDOWS:
            self.meson_options['werror'] = 'false'
